package davidtps.godutch.activity.base;

import junit.framework.Test;
import davidtps.godutch.activity.R;
import davidtps.godutch.controls.SlideMenuView;
import davidtps.godutch.controls.SlideMenuViewItem;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ActivityFrame extends ActivityBase {

	private SlideMenuView _SlideMenuView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		setContentView(R.layout.main);
	}

	public void changeAppTopTitle(String pTitle) {
		TextView _TextView = (TextView) findViewById(R.id.tvTopTitle);
		_TextView.setText(pTitle);
	}
	
	public void addBackListener(){
		ImageView mImageView = (ImageView)findViewById(R.id.ivBackImageView);
		mImageView.setVisibility(ImageView.VISIBLE);
		mImageView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}

	public void attachMainBody(int pResId) {
		LinearLayout _LinearLayout = (LinearLayout) findViewById(R.id.lmaincontent);
		View _View = LayoutInflater.from(this).inflate(pResId, null);

		LayoutParams _LayoutParams = new LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

		_View.setLayoutParams(_LayoutParams);
		_LinearLayout.addView(_View);
	}
	
	public void attachMainBody(View pView){
		LinearLayout _LinearLayout = (LinearLayout) findViewById(R.id.lmaincontent);
		_LinearLayout.addView(pView);
	}

	public void createSlideMenuList(int pArrayMenuResource) {
		_SlideMenuView = new SlideMenuView(this);

		String[] menuArray = getResources().getStringArray(pArrayMenuResource);
		for (int i = 0; i < menuArray.length; i++) {
			SlideMenuViewItem _SlideMenuViewItem = new SlideMenuViewItem();

			_SlideMenuViewItem.setMenuItemId(i);
			_SlideMenuViewItem.setMenuItemTitle(menuArray[i]);
			_SlideMenuView.add(_SlideMenuViewItem);
		}
	}

	public void closeSlideMenuList() {
		_SlideMenuView.toggle();
	}
	
	public boolean isClosed(){
		return _SlideMenuView.isClosed();
	}
	
	public void removeSlideMenu(){
		new SlideMenuView(this).removeSlideMenu();
	}

	public void createContextMenu(Menu pMenu) {
		int _Item[] = { 1, 2 };
		int _GroupID = 0;
		int _Order = 0;
		for (int i = 0; i < _Item.length; i++) {
			switch (_Item[i]) {
			case 1:
				pMenu.add(_GroupID, _Item[i], _Order,
						R.string.comm_menu_update_string);
				break;
			case 2:
				pMenu.add(_GroupID, _Item[i], _Order,
						R.string.comm_menu_delete_string);
				break;
			default:
				break;
			}
		}
	}

}
